package com.hrpmar.controller;

import com.hrpmar.controller.dto.ProviderDto;
import com.hrpmar.pojo.Provider;
import com.hrpmar.service.ProviderService;
import com.hrpmar.utils.Pager;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;



/**
 * Created by dell on 2017/11/17.
 */
@RestController
@RequestMapping("/provider")
public class ProviderRestController {

    @Resource
    private ProviderService providerService;
    String msg = null;

    @GetMapping("/search")
    public Pager search(Integer offset, Integer limit, ProviderDto dto){
        return providerService.getProviderByDto(offset,limit,dto);
    }

    @PostMapping("/addPro")
    public String addProInfo(Provider provider){
        try{
            providerService.addPro(provider);
            msg="添加供应商信息成功！";
        }catch (RuntimeException e){
            msg="添加供应商信息失败！";
        }
        return msg;
    }

    @PostMapping("/updatePro")
    public String updateProInfo(Provider provider){
        try{
            providerService.updatePro(provider);
            msg="修改供应商信息成功！";
        }catch (RuntimeException e){
            msg="修改供应商信息失败！";
        }
        return msg;
    }

    @PostMapping("/delPro")
    public String delPro(Integer proId){
        try{
            providerService.delPro(proId);
            msg="删除供应商信息成功！";
        }catch (RuntimeException e){
            msg="删除供应商信息失败！";
        }
        System.out.println(msg);
        return msg;
    }

    @PostMapping("/getPro")
    public Provider getProById(Integer proId){
        return  providerService.getProviderById(proId);
    }
}
